home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacsBug / MacsBug 6.1 / dcmds / C Samples / Heap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-21  |  1.7 KB  |  80 lines  |  [TEXT/MPS ]

  1. /* Heap.c
  2.  
  3.    The following MPW commands will build the dcmd and copy it to the
  4.    "Debugger Prefs" file in the System folder. The dcmd's name in
  5.    MacsBug will be the name of the file built by the Linker.
  6.  
  7.         C Heap.c -b
  8.         Link {dcmdLib}dcmdGlue.a.o Heap.c.o {dcmdLib}DRuntime.o {CLibraries}StdCLib.o -o Heap
  9.         BuildDcmd Heap 100
  10.  */
  11.  
  12. #include <Types.h>
  13. #include "dcmd.h"
  14.  
  15.  
  16. void NumberToHex (long number, Str255 hex)
  17. {
  18.     Str255    digits = "0123456789ABCDEF";
  19.     int        n;
  20.  
  21.     strcpy (hex, &".00000000");
  22.     hex[0] = 8;
  23.     for (n = 8; n >= 1; n--)
  24.         {
  25.         hex[n] = digits[number % 16];
  26.         number = number / 16;
  27.         }
  28. } // NumberToHex
  29.  
  30.  
  31. pascal void DisplayBlockInfo (long blockAddress, long blockLength, long masterPtr, short blockType, Boolean locked, Boolean purgeable, Boolean resource)
  32. {
  33.     Str255 value;
  34.  
  35.     NumberToHex (blockAddress, value);
  36.     dcmdDrawLine (value);
  37.  
  38.     NumberToHex (blockLength, value);
  39.     dcmdDrawString ("\p ");
  40.     dcmdDrawString (value);
  41.  
  42.     if (blockType == relocatableBlock)
  43.         {
  44.         NumberToHex (masterPtr, value);
  45.         dcmdDrawString ("\p ");
  46.         dcmdDrawString (value);
  47.  
  48.         dcmdDrawString ("\p ");
  49.         if (locked)
  50.             { dcmdDrawString ("\pLocked "); }
  51.         if (purgeable)
  52.             { dcmdDrawString ("\pPurgeable "); }
  53.         if (resource)
  54.             { dcmdDrawString ("\pResource "); }
  55.         }
  56. } // DisplayBlockInfo
  57.  
  58.  
  59. pascal void CommandEntry (dcmdBlock* paramPtr)
  60. {
  61.     switch (paramPtr->request)
  62.         {
  63.         case dcmdInit:
  64.             break;
  65.  
  66.         case dcmdHelp:
  67.             dcmdDrawLine ("\pHEAP");
  68.             dcmdDrawLine ("\p   Displays information about all heap blocks");
  69.             break;
  70.  
  71.         case dcmdDoIt:
  72.             // Draw the column labels
  73.             dcmdDrawLine ("\p  Address   Length  Mstr Ptr");
  74.  
  75.             // The MacsBug heap iterator will call DisplayBlockInfo once for each block in the heap
  76.             dcmdForAllHeapBlocks (DisplayBlockInfo);
  77.             break;
  78.         }
  79. } // CommandEntry
  80.